package com.prs.crm.action.stu;

import java.util.List;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;
import org.courser.struts.BaseAction;
import org.courser.ui.PaginationSupport;
import org.hibernate.criterion.DetachedCriteria;

import com.prs.crm.domain.student.Grades;
import com.prs.crm.domain.student.Student;
import com.prs.crm.service.stu.GradesService;
import com.prs.crm.service.stu.StudentService;
/**
 * 
 * @author 廖苹宏
 * @E-mail 295609175@qq.com
 * @version 创建时间：2012-4-25 10:32:20 学生信息
 */
public class StuAction extends BaseAction{
	private static final long serialVersionUID = 1L;
	private StudentService studentService;
	private Student student;
	private PaginationSupport pagination;
	private List<Grades> grades;
	private GradesService gradesService;
	public StudentService getStudentService() {
		return studentService;
	}
	public void setStudentService(StudentService studentService) {
		this.studentService = studentService;
	}
	public Student getStudent() {
		return student;
	}
	public void setStudent(Student student) {
		this.student = student;
	}	
	public PaginationSupport getPagination() {
		return pagination;
	}
	public void setPagination(PaginationSupport pagination) {
		this.pagination = pagination;
	}	
	public List<Grades> getGrades() {
		return grades;
	}
	public void setGrades(List<Grades> grades) {
		this.grades = grades;
	}
	public GradesService getGradesService() {
		return gradesService;
	}
	public void setGradesService(GradesService gradesService) {
		this.gradesService = gradesService;
	}
	///////////////////以下为业务///////////////////////
	@Action("liststudent")
	public String list(){
		DetachedCriteria criteria = this.getPaginationHelper().createQuery(Student.class);
		this.setPagination(this.getStudentService().
				listByPage(criteria, this.getPaginationHelper().prepare(pagination)));
		return SUCCESS;
	}
	//新增
	@Action(value="saveStudent",results={
			@Result(name = "success", type = "redirect", location = "liststudent"),
			@Result(name = "error", type = "chain", location = "edistudent") })
	public String saveStudent(){
		this.studentService.save(student);
		return SUCCESS;
	}
	//修改
	@Action("edistudent")
	public String edistudent(){
		grades = this.gradesService.getAllGrade();
		return SUCCESS;
	}
	//删除
	@Action(value="remove",results={
			@Result(name = "success", type = "redirect", location = "liststudent"),
			@Result(name = "error", type = "chain", location = "liststudent") })
	public String remove(){
		this.studentService.remove(student);
		return SUCCESS;
	}
}
